<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.cqggrw.util.*"%>
<%@ page import="com.cqggrw.domain.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String id = request.getParameter("id");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>公共人物网后台管理</title>
<link type="text/css" rel="Stylesheet"
	href="<%=basePath%>Admin/Content/tabbed_pages.css" />
<link type="text/css" rel="Stylesheet"
	href="<%=basePath%>Admin/Content/Index.css" />
<script type="text/javascript" src="<%=basePath%>jslib/calendar.js"></script>
<script type="text/javascript"
	src="<%=basePath%>jslib/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=basePath%>jslib/utils.js"></script>
<script type="text/javascript"
	src="<%=basePath%>jslib/ueditor/editor_config.js"></script>
<script type="text/javascript"
	src="<%=basePath%>jslib/ueditor/editor_all_min.js"></script>
<script type="text/javascript">
	var editor = undefined;
	var idStr =<%=id%>;
	var imgFalg = undefined;
	$(function() {
		editor = new UE.ui.Editor();
		editor.render("myEditor");

		editor.ready(function() {
					editor.setContent('');
					editor.setHeight(250);

					$.ajax({
								url : '${pageContext.request.contextPath}/newsAction!getOne.action?id='
										+ idStr,
								type : 'POST',
								dataType : 'json',
								success : function(news) {
									if (news) {
										$("#name").val(news.name);
										$("#id").val(news.id);
										$("#type").val(news.type);
										$("#addDate").val(news.addDate);
										editor.setContent(news.content);
										$("#txtcontent").val(news.txtContent);
										if (news.ckbIsPass == 1)
											$("#ckbIsPass").attr("checked",	true);
										if (news.ckbtop == 1)
											$("#ckbtop").attr("checked", true);
										if (news.cknishot == 1)
											$("#cknishot")	.attr("checked", true);
										//imgFalg = news.falg;
										//console.log(imgFalg);
										//loadImg();
									}
								}
							});
				});
	});
	function WebForm_OnSubmit() {
		if ($("#name").val() == '') {
			alert('请填写-新闻题目：');
			return false;
		} else if ($("#type").val() == -1) {
			alert('请填写-新闻类型：');
			return false;
		} else if ($("#addDate").val() == '') {
			alert('请填写-发布日期：');
			return false;
		} else if ($("#addUser").val() == '') {
			alert('请填写-发布人：');
			return false;
		} else if (editor.getContent() == '') {
			alert('请填写-详细类容：');
			return false;
		} else if ($("#txtcontent").val() == '') {
			alert('请填写-类容提取：');
			return false;
		}
		return true;
	}

	function WebForm_DoPostBackWithOptions() {
		var name = $('#name').val();
		var txt = editor.getContent();

		var start = 0;
		var end = txt.indexOf('</p>', start);
		while (true) {
			if (end == -1) {
				editor.setContent(txt);
				break;
			}
			var tmp = txt.substring(start, end) + '</p>';
			editor.setContent(tmp);
			tmp = editor.getContentTxt();
			tmp = tmp.replace(/ /g, "");
			if (tmp != name && tmp.length > 20) {
				$('#txtcontent').val(tmp);
				editor.setContent(txt);
				break;
			}

			start = end + 4;
			end = txt.indexOf('</p>', start);
		}
	}
</script>
<style type="text/css">
.productImage {
	float: left;
	width: 200px;
	margin-left: 20px;
}

.productImage img {
	width: 200px;
	height: 150px;
}
</style>
</head>
<body>
	<form name="form1" method="post" action="newsAction!modify.action"
		onsubmit="javascript:return WebForm_OnSubmit();" id="form1"
		enctype="multipart/form-data">
		<input type="hidden" name="id" id="id" />
		<div class="form-div textLeft">
			<h1>
				<span class="action-span"><a href="NewList.jsp">新闻列表</a> </span> <span
					class="action-span1 fs20">公共人物网 管理中心 </span><span
					class="action-span1 paddingTop5"> - 新闻编辑 </span>
			</h1>
			<div style="clear:both"></div>
		</div>
		<div id="gallery">
			<div class="on" title="CommonInfo">
				<span>新闻信息</span>
			</div>
		</div>
		<div id="CommonInfo" class="show">
			<table width="90%" id="general-table" align="center">
				<tr>
					<td>新闻题目： <input name="name" type="text" maxlength="60"
						id="name" style="width:318px;" /> <span
						id="RequiredFieldValidator1" style="color:Red;visibility:hidden;">*</span>
					</td>
				</tr>
				<tr>
					<td>新闻类型： <select name="type" id="type" MaxLength="30"
						style="height:20px;width:182px;">
							<option value="-1">请选择...</option>
							<%
								Connection conn = null;
								PreparedStatement ps = null;
								ResultSet rs = null;

								String sql = "SELECT * FROM tbl_category;";
								try {
									conn = DBUtil.getConn();
									ps = conn.prepareStatement(sql);
									rs = ps.executeQuery();

									while (rs.next()) {

										out.println("<option value=\"" + rs.getInt("id") + "\">"
												+ rs.getString("name") + "</option>");
									}
								} catch (Exception e) {
									e.printStackTrace();
								} finally {
									DBUtil.close(conn, ps, rs);
								}
							%>
					</select> &nbsp;<span id="RequiredFieldValidator2"
						style="color:Red;visibility:hidden;">*</span>
					</td>
				</tr>
				<tr>
					<td>发布日期： <input name="addDate" type="text" maxlength="10"
						id="addDate" /> <input name="selbtn1" type="button" id="selbtn1"
						onclick="new Calendar().show(this.form.addDate);" value="选择"
						class="button" /> <span id="RequiredFieldValidator4"
						style="color:Red;visibility:hidden;">*</span>
					</td>
				</tr>
				<tr>
					<td>发&nbsp; 布&nbsp; 人：<input name="addUser" type="text"
						value="admin" maxlength="30" id="TextBoxReleaseName"
						readonly="readonly" /> &nbsp;<span id="RequiredFieldValidator3"
						style="color:Red;visibility:hidden;">*</span> 来源：<input
						name="comfrom" type="text" value="公共人物网" id="comfrom" />
					</td>
				</tr>
				<tr>
					<td>
						<table>
							<tr>
								<td>详细类容：</td>
								<td>
									<div>
										<textarea name="content" id="myEditor"></textarea>
									</div></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table>
							<tr>
								<td>类容提取：</td>
								<td><textarea name="txtContent" rows="2" cols="20"
										id="txtcontent" style="height:95px;width:717px;">
</textarea> <input type="button" name="Button1" value="自动获取"
									onclick="javascript:WebForm_DoPostBackWithOptions()"
									id="Button1" /></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>文字属性： <input id="ckbIsPass" type="checkbox" value="1"
						name="ckbIsPass" checked="checked" /><label for="ckbIsPass">通过审核</label>
						:<input id="ckbtop" type="checkbox" value="1" name="ckbtop" /><label
						for="ckbtop">头条推荐</label><input id="cknishot" type="checkbox"
						value="1" name="cknishot" /><label for="cknishot">热点推荐</label>
					</td>
				</tr>
			</table>
		</div>
		<div class="form-div textLeft"
			style="text-align:center;margin-top:5px;">
			<input type="submit" name="btnSave" value="保存" id="btnSave"
				class="button" />
		</div>
	</form>
	<script type="text/javascript">
	function loadImg() {
		$.getJSON("${pageContext.request.contextPath}/newsAction!getNewsImg.action", {falg : imgFalg}, function(data){
			var divHtml = '';
			console.log(data);
			console.info(data.length);
			for(var i = 0; i < data.length; i++) {
				divHtml = divHtml + '<div id="'+data[i].falg+data[i].id+'">图片描述：'+data[i].des
				+'<br/>图片名：'+data[i].name+'</div>';
			}
			if(divHtml.length > 0) {
				$('#newsImg').html(divHtml);
			}
			});
	}
	</script>
</body>
</html>